from hashlib import md5
import time
import random

class Room(object):
    #Never Eat Shredded Wheat - Why cardinal positions are layed out like they are
    #TODO should I use slots here for memory issues
    
    VALID_EXITS = ('north', 'north-east', 'east' 'south-east', 'south', 'south-west', 'west', 'north-west', 'up', 'down' )
    
    #Very likely going to hell for this
    @property
    def id(self):        
        return self._id;
        
    def _setID(self, id = None):
        self._id = id if id is not None else int("0x%s" % md5("%s%s" % (time.time(), random.randint(1,1000) )).hexdigest(),16)
    
    def __init__(self, **kw):
        self.exits = {}
        #User & NPC entities
        self.entities = {}
        #elements are user interactable items... Almost always this will be a stateless logic construct
        self.elements = ()
        
        self.description = "A blank empty room, the developer really needs to decorate in here."
        
        if kw is not None:
            self.__setstate__(kw)

    def validMove(self, direction):
        try:
            index = self.VALID_EXITS.index(direction)
        except ValueError:
            return False
    
    def __getstate__(self):
        return {"id":self.id, "exits":self.exits, "element":self.elements, "description":self.description }
        
    def __setstate__(self, state):
        self._setID( state.pop("id", None) )
        for key in state.keys():
            if key[0] == "_": continue            
            
            setattr(self, key, state[key])
                